'use strict';

const colors = require('colors');

const THRESHOLD_NUMBER = 5000;

function sleep() {
    function fibonacci(n) {
        return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
    }

    //fibonacci(45);
    fibonacci(40);
}

function* parserGenerator() {
    for(let i = 0; i < THRESHOLD_NUMBER; ++i) {
        //sleep();
        //yield parseInt('0xFF', 16) + i * 10;
        yield i;
    }
}

let handler = setInterval(() => console.log('heartbeat'.gray), 200);

!async function() {

    let generator = parserGenerator();
    setTimeout(function doWork() {
        let step = generator.next();
        if (step.done) {
            console.log('GET FINAL RESULT'.red.bold);
        }
        else {
            let value = step.value;
            console.log(`get number now [${value}]`.yellow.bold);
            setTimeout(doWork, 0);
        }
    }, 0);

    await new Promise(resolve => setTimeout(resolve, 10 * 1000));
    console.log('ALL DONE'.green.bold);
    clearInterval(handler);
}();
